package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.List;

import com.xcity.game.task.Task;
import com.xcity.game.task.Task.State;
import com.xcity.game.task.TaskTemplate;

import naga.x.App;
import naga.x.game.template.TemplateService;
import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@Deprecated
@PomeloMessage(type = Message.Type.RESPONSE)
public class DailyTaskListResponse extends Response {
	private List<TaskInfo> tasks;

	public static class TaskInfo {
		private int id;
		private String name;
		private String desc;
		private boolean isReceived;
		private int curnum;
		private int maxnum;
		private List<TaskRewardInfo> goods;

		public int getId() {
			return id;
		}

		public void setId(int id) {
			this.id = id;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getDesc() {
			return desc;
		}

		public void setDesc(String desc) {
			this.desc = desc;
		}

		public boolean isIsReceived() {
			return isReceived;
		}

		public void setIsReceived(boolean isReceived) {
			this.isReceived = isReceived;
		}

		public int getCurnum() {
			return curnum;
		}

		public void setCurnum(int curnum) {
			this.curnum = curnum;
		}

		public int getMaxnum() {
			return maxnum;
		}

		public void setMaxnum(int maxnum) {
			this.maxnum = maxnum;
		}

		public List<TaskRewardInfo> getGoods() {
			return goods;
		}

		public void setGoods(List<TaskRewardInfo> goods) {
			this.goods = goods;
		}
	}

	public static class TaskRewardInfo {
		// Task.REWARD_GOLD = 0; // 现金
		// Task.REWARD_STONE = 1; // 钻石
		// Task.REWARD_EXP = 2; // 经验
		private byte id;
		private int num;
		public TaskRewardInfo(int id, int num) {
			this.id = (byte) id;
			this.num = num;
		}

		public byte getId() {
			return id;
		}

		public void setId(byte id) {
			this.id = id;
		}

		public int getNum() {
			return num;
		}

		public void setNum(int num) {
			this.num = num;
		}
	}
	
	public DailyTaskListResponse(int serial, List<Task> srcs) {
		super(serial);
		tasks = new ArrayList<TaskInfo>(srcs.size());
		for (int i = 0; i < srcs.size(); i++) {
			Task src = srcs.get(i);
			TaskTemplate template = App.getApp().getServiceManager().get(TemplateService.class).get(TaskTemplate.class, src.getId());
			TaskInfo task = new TaskInfo();
			tasks.add(task);
			task.id = src.getId();
			task.name = template.getName();
			task.desc = template.getDesc();
			task.isReceived = src.getState() == State.REWARDED;
			task.curnum = src.getProgress();
			task.maxnum = 0;//template.getCondition();
			List<TaskRewardInfo> rewards = new ArrayList<TaskRewardInfo>(3);
			task.goods = rewards;
			// Task.REWARD_GOLD = 0; // 现金
			// Task.REWARD_STONE = 1; // 钻石
			// Task.REWARD_EXP = 2; // 经验
			if (template.getGold() > 0) {
				rewards.add(new TaskRewardInfo(0, template.getGold()));
			}
			if (template.getStone() > 0) {
				rewards.add(new TaskRewardInfo(1, template.getStone()));
			}
			if (template.getExp() > 0) {
				rewards.add(new TaskRewardInfo(2, template.getExp()));
			}
		}
	}

	public List<TaskInfo> getTasks() {
		return tasks;
	}

	public void setTasks(List<TaskInfo> tasks) {
		this.tasks = tasks;
	}
}
